<% privateStudentMode = ((user_signed_in? and current_subject.role?("PrivateStudent")) or (profile_subject.role?("PrivateStudent"))) %>

<div class="btn-group">

  <!--BTN ADD-->
 <% if !profile_subject_is_current? and !privateStudentMode %>
    <div class="btn btn-follow">
      <%= contact_button(profile_subject) %>
    </div>
  <% end %>

  <!-- Edit your profile -->
  <% @profile = profile_or_current_subject.profile %>
  <% if can?(:update, @profile) %>
    <div class="edit_icon btn btn-secundary">
      <%= link_to(raw("<i class='fa fa-edit '></i>")+ t('profile.edit'), '#', :id => "edit_icon_link") %>
    </div>
  <% end %>

  <!-- Manage user (only for admins) -->
  <% if can?(:edit_roles, @profile) %>
      <div class="edit_icon btn btn-default">
        <a href="#AdminUserModal" id="showModalAdmin" data-toggle="modal">
          <%= raw("<i class='fa fa-wrench'></i>")+ t('admin.modal.manage_user_button')%>
        </a>
      </div>
  <% end %>

  <!--BTN MESSAGE-->
  <% if !profile_subject_is_current? and user_signed_in? and !privateStudentMode %>
    <button href="#new_messages_profile" id="mesage-profile" role="button" class="btn btn-secundary" data-toggle="modal" data-remote="false">
      <%= link_to new_message_path(receiver: profile_subject.slug) do %>
      <i class="fa fa-envelope-o"></i>
      <%= t 'mailboxer.send' %>
      <% end %>
    </button>
  <% end %>

  <!--BTN show-more-->
  <a class="expand btn btn-secundary" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseInfo">
    <span id="showingMore" class="showMore accordion-toggle " data-toggle="collapse" data-parent="#accordion2" href="#collapseOne" title=<%=t("excursion.actions.show_more")%> status="collapsed">
      <i class="fa fa-plus-square-o"></i><%=t('excursion.actions.show_more')%>
    </span>
  </a>

</div>


<% if can?(:edit_roles, @profile) %>
    <div id="AdminUserModal" class="modal fade">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">
              <span aria-hidden="true">&times;</span><span class="sr-only"><%=t("close")%></span>
            </button>
            <h4>
              <%= t('admin.modal.title') %> <%=profile_subject.name%>
            </h4>
          </div>

          <div class="modal-body">
            <!-- change role -->
            <div class="admin_section">
              <p><%= t('admin.modal.change_role') %></p>
              <hr>
              <form action=<%=update_role_user_path(profile_subject)%> method="post">
                <%= token_tag nil %>
                <%= select_tag(:role, user_roles_options_for_select(profile_subject.role.id))%>
                <input type="submit" class="btn btn-primary update_section" value="<%=t('button.update')%>">
              </form>
            </div>

            <!-- permissions -->
            <div class="admin_section">
              <p><%= t('admin.modal.permissions') %></p>
              <hr>
              <form action=<%=service_permissions_update_permissions_path%> method="post">
                <%= token_tag nil %>
                <%= hidden_field_tag :owner_id, profile_subject.actor_id %>
                <%ServicePermission.all_keys.each do |key|%>
                  <input type="checkbox" name="sp[]" <%="checked" if profile_subject.has_permission(key)%> value="<%=key%>"> <span class="lbl padding-4"><%=t("permissions." + key)%></span>
                <%end%>
                <input type="submit" class="btn btn-primary update_section" value="<%=t('button.update')%>">
              </form>
            </div>

            <!-- delete user -->
            <div class="admin_section">
              <p><%= t('admin.modal.delete_user') %></p>
              <hr>
              <%= link_to(raw("<i class='fa fa-trash'></i> ")+ t('profile.remove'), user_path(profile_subject), :confirm => t('are_you_sure'), :method => "delete", :class => "btn btn-primary update_section")%>
            </div>
          </div>

          <!--<div class="modal-footer">
            <button type="button" class="btn btn-primary" data-dismiss="modal"><%=t("close")%></button>
          </div>-->

        </div>
      </div>
  </div>

<% end %>


<%content_for :javascript do%>
  $("#showingMore").click(function(e){
    if($("#showingMore").attr("status")==="expanded"){
      $("#showingMore").html('<i class="fa fa-plus-square-o"></i> <%=t("excursion.actions.show_more")%>');
      $("#showingMore").attr("title", "<%=t('excursion.actions.show_fewer')%>");
      $("#showingMore").attr("status", "collapsed");
    }
    else{
      $("#showingMore").html('<i class="fa fa-minus-square-o"></i><%=t("excursion.actions.show_fewer")%>');
      $("#showingMore").attr("title", "<%=t('excursion.actions.show_more')%>");
      $("#showingMore").attr("status", "expanded");
    }
  });

    var sendMessage = $("input[name='send_message']");
    var send = $("input[type='button'][value='<%=t('mailboxer.send')%>']");
    $(sendMessage).addClass("hidden");
    $(send).click(function(event) {
      $(sendMessage).click();
    });
    var SSMInitiated = false;
    $('#new_messages_profile').on('shown.bs.modal', function () {
      if(!SSMInitiated){
       SocialStream.Message.new_();
       SSMInitiated = true;
     }
   })
    $('#new_messages_profile').on('hidden.bs.modal', function () {
      $("#mesage-profile").removeAttr("href");
      $("#mesage-profile").removeAttr("data-toggle");
      $("#mesage-profile").removeAttr("data-remote");
    })
<%end%>
